#!/bin/bash
#
# FTPs files from a FTP Server
# build script.
#
function getRemoteFiles {

   FTP_SERVER=$1
   REMOTE_FILE=$2
   REMOTE_DIR=`/usr/bin/dirname ${REMOTE_FILE}`
   FILE=`basename ${REMOTE_FILE}`
   USER=$3
   PASS=$4
   # remove it first
   if [ -d /usr/local/hsc_install.images/ ]
   then
      rm -rf /usr/local/hsc_install.images/*
   fi
   ftp -n $FTP_SERVER <<EOF 2>&1 >/tmp/ftp.log
user $USER $PASS
bin
cd $REMOTE_DIR
get $REMOTE_FILE /usr/local/hsc_install.images/$FILE
quit
EOF
   if [ -f /usr/local/hsc_install.images/$FILE ]
   then
       return 0
   else
       return 1
   fi
} # end function getRemoteFiles

if [ "$1" = "" ]
then
   echo "Usage: getRemoteFiles <ftp server> <remote file> <user> <password>"
   exit 1
fi

getRemoteFiles $1 $2 $3 $4 
exit $?

